﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

using System.IO.IsolatedStorage;

namespace GPA_Calculator
{
    public partial class Settings : PhoneApplicationPage
    {
        public Settings()
        {
            InitializeComponent();
        }
        private float minorInterval { get; set; }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            minorInterval = App.getMinorIntervalFromStorage();

            // Set default
            if (minorInterval == 0.3F)
            {
                scale43.IsChecked = true;
            }
            else
            {
                scale45.IsChecked = true;
            }
        }

        private void scaleRadio_Click(object sender, RoutedEventArgs e)
        {
            if (scale43.IsChecked == true)
            {
                // 4.3 scale
                setMinorIntervalSetting(0.3F);
            }
            else
            {
                // 4.5 scale
                setMinorIntervalSetting(0.5F);
            }
        }

        private void setMinorIntervalSetting(float minorInterval)
        {
            IsolatedStorageSettings iss = IsolatedStorageSettings.ApplicationSettings;

            string key = App.MinorIntervalKey;

            if (iss.Contains(key))
            {
                iss[key] = minorInterval;
            }
            else 
            {
                iss.Add(key, minorInterval);
            }
        }
    }
}